#ifndef __WHITEBOARDMANAGER_H__
#define __WHITEBOARDMANAGER_H__

#include "MyThread.h"
#include "ListPtr.h"
#include "Lock.h"
#include "WB.h"

typedef struct tagSaveWbData
{
	char	*pData;
	int		nDataLen;
}SaveWbData;

class CManager;
class CWhiteBoardManager : public CMyThread
	, CWBCallback
{
public:
	CWhiteBoardManager(CManager *pMan);
	~CWhiteBoardManager(void);

	bool InitWhiteBoard(string strFilePath, int nLanguageType = 0);
	uint32_t GetWindowHandle(void);

	void ReSetTerminalId();

	void EnableDataOperationRight(bool bEnable);
	void EnadleSync(bool bEnable);

	void HandleRecvWBData(const char *pData, int nDataLen);
	void CompleteFileReceivingTask(void);

	void SetLocalMode(bool bLocal);
	void ClearLocalWbData(void);

	void GetWbData(void);
	void ClearSaveWbData(void);

protected:
	//CMyThread
	virtual void ThreadProcMain(void);
	//CWBCallback 
	virtual void OnSendWBFile(char* fileName, uint32_t fileId);
	virtual void OnSendWBMessage(uint8_t* buffer, uint32_t size, uint32_t destId = 0);
	virtual void OnSendWBViewScrollPos(uint32_t pos1, uint32_t pos2) ;
	virtual void OnCancelFileSendingTask(uint32_t fileId);
	virtual bool CanSendWbSyncMessage();
	virtual bool OnControlButton(uint32_t controlType);
	virtual void OnSendWbSavePath(char* pWbSavePath, char* pWbFileName);

private:
	void HandleSendFile(void *pParam);
	bool InitFileHanlde(const char *pFileName, int nTerminalId);

	int SendFileStart(const char *pData, int nDataLen);
	int SendFileData(const char *pData, int nDataLen);

	int SendFileEnd(void);
	void SaveRecvWbData(char *pData, int nDataLen);

	void ClearSaveRecvWbData(void);

private:
	CWhiteboard					*m_pWhiteBoard;
	CManager					*m_pMan;

	string						m_strPath;
	bool						m_bExit;

	ListPtr						m_lstSendFile;
	CLock						m_lockSendFile;

	ListPtr						m_lstSaveWb;
	CLock						m_lockSaveWb;

	char						*m_pFileBuff;
	int							m_nFileLen;

	bool						m_bSync;
	bool						m_bLocalWb;
};

#endif
